﻿using FDStudio.Core.Entities;
using FDStudio.Core.Entities.Enums;
using FDStudio.Core.Extensions;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;

namespace FDStudio.Core.Config
{
    /*
     CreatedOn: 2018-01-27
     CreatedBy: Jackie Lee(天宇遊龍)
     */
    /// <summary>
    /// 配置管理
    /// </summary>
    public sealed class ConfigurationManager
    {
        private IConfiguration _configuration;

        public ConfigurationManager(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public T GetSection<T>(string name)
        {
            var config = _configuration.GetSection(name);
            if (config != null)
            {
                return config.Value.FromJson<T>();
            }
            return default(T);
        }

        /// <summary>
        /// 当前数据库配置
        /// </summary>
        /// <returns></returns>
        public IList<DbConnectionConfig> GetDbConnections()
        {
            return GetSection<IList<DbConnectionConfig>>("DbSetting");
        }
    }
}
